package org.infodavid.common.persistence;

import javax.persistence.PersistenceException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.infodavid.common.model.ITemplateCategory;
import org.infodavid.common.persistence.impl.AbstractDataService;
import org.infodavid.common.reflect.InstantiationHelper;

/**
 * The Class TemplateCategoryDataService.
 */
public abstract class TemplateCategoryDataService extends
    AbstractDataService<ITemplateCategory,Long> {

  /** The singleton. */
  private static final TemplateCategoryDataService SINGLETON;

  /** The Constant log. */
  private static final Log LOGGER = LogFactory.getLog(TemplateCategoryDataService.class);

  static {
    try {
      SINGLETON = InstantiationHelper.getInstance().newInstance(TemplateCategoryDataService.class);
    }
    catch (final Exception e) {
      LOGGER.fatal("Can not instantiate the " + TemplateCategoryDataService.class.getName(), e);

      throw new Error(e);
    }
  }

  /**
   * returns the singleton.
   * @return the singletons
   */
  public static TemplateCategoryDataService getInstance() {
    return SINGLETON;
  }

  /**
   * Instantiates a new service.
   */
  protected TemplateCategoryDataService() {
    super();
  }

  /**
   * Find by name.
   * @param session the session
   * @param value the value
   * @return the category
   * @throws PersistenceException the persistence exception
   */
  public abstract ITemplateCategory findByName(PersistenceSession session, String value)
      throws PersistenceException;
}
